package com.fdd.op.sdk.request.api.unwantedauthsign;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fdd.op.sdk.ApiRuleException;
import com.fdd.op.sdk.BaseFddRequest;
import com.fdd.op.sdk.constants.Constants;
import com.fdd.op.sdk.internal.mapping.RequestField;
import com.fdd.op.sdk.internal.util.FddHashMap;
import com.fdd.op.sdk.internal.util.StringUtils;
import com.fdd.op.sdk.response.api.unwantedauthsign.OpenUnwantedAuthSignResponse;

import java.util.Date;
import java.util.Map;

public class OpenUnwantedAuthSignRequest extends BaseFddRequest<OpenUnwantedAuthSignResponse> {

    public String getApiMethodName() {
        return "/base/api/unwantedAuthSign/openUnwantedAuthSign";
    }

    @Override
    public Map<String, Object> getTextParams() {
        FddHashMap txtParams = new FddHashMap();
        if(this.udfParams != null) {
            txtParams.putAll(this.udfParams);
        }
        return txtParams;
    }

    @Override
    public Class<OpenUnwantedAuthSignResponse> getResponseClass() {
        return OpenUnwantedAuthSignResponse.class;
    }

    @Override
    public void check() throws ApiRuleException {
        if(getAuthorizerFlag() != 1 && getAuthorizerFlag() != 2){
            throw new ApiRuleException(null, "authorizerFlag只能取1或者2");
        }
        if(getUrlTimeOut() != null && (getUrlTimeOut() < 0 || getUrlTimeOut() > 525600)) {
            throw new ApiRuleException(null, "urlTimeOut取值范围为0-525600的正整数");
        }
        if(getAccessType() != 0 && getAccessType() != 1 && getAccessType() != 2){
            throw new ApiRuleException(null, "accessType只能取0、1、2。");
        }
        if(StringUtils.isNotBlank(getAccessCode()) && getAccessCode().length() > 6){
            throw new ApiRuleException(null, "访问码不能超过6位");
        }
        if(StringUtils.isBlank(getNotifyUrl())){
            throw new ApiRuleException(null, "notifyUrl不能为空");
        }else if(getNotifyUrl().length() > 2048){
            throw new ApiRuleException(null, "notifyUrl不能超过2048位");
        }
        if(getIsSendSms() != 0 && getIsSendSms() != 1){
            throw new ApiRuleException(null, "isSendSms,发送开通短信,传[0,1]");
        }
    }

    @Override
    public String getHttpMethod() {
        return Constants.METHOD_POST;
    }

    @RequestField(value = "授权主体类型：1个人, 2企业")
    private int authorizerFlag;

    @RequestField(value = "授权主体在当前系统的唯一标识，个人主体传accountId，企业主体传companyId")
    private String authorizerTargetId;

    @RequestField(value = "授权主体在第三方业务系统的唯一标识，个人主体传tpAccountId，企业主体传tpOrgId")
    private String tpAuthorizerTargetId;

    @RequestField(value = "企业授权主体管理员在当前系统的唯一标识")
    private String adminAccountId;

    @RequestField(value = "企业授权主体管理员在第三方业务系统的唯一标识")
    private String adminTpAccountId;

    @RequestField(value = "URL有效期，以分钟为单位进行设置，大于等于0的正整数，不传则默认10080分钟（7天），最长有效期为一年，传0则默认按最长有效期")
    private Integer urlTimeOut;

    @RequestField(value = "页面访问方式,0：不做访问限制（默认）；1：访问码；2：手机验证码")
    private int accessType = 0;

    @RequestField(value = "页面访问码，签署验证方式为访问码时必填，平台方自定义，填写了则需要填入访问码才能打开本接口返回的签署链接。适用于平台方业务系统自行向用户发送签署链接时使用。")
    private String accessCode;

    @RequestField(value = "异步回调地址，在免验证签授权成功后，向该地址进行授权信息回调")
    private String notifyUrl;

    @RequestField(value = "是否发送开通短信，1:发送，0:否，默认是0")
    private int isSendSms;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @RequestField("授权有效期")
    private Date effectiveTime;

    public int getAuthorizerFlag() {
        return authorizerFlag;
    }

    public void setAuthorizerFlag(int authorizerFlag) {
        this.authorizerFlag = authorizerFlag;
    }

    public String getAuthorizerTargetId() {
        return authorizerTargetId;
    }

    public void setAuthorizerTargetId(String authorizerTargetId) {
        this.authorizerTargetId = authorizerTargetId;
    }

    public String getTpAuthorizerTargetId() {
        return tpAuthorizerTargetId;
    }

    public void setTpAuthorizerTargetId(String tpAuthorizerTargetId) {
        this.tpAuthorizerTargetId = tpAuthorizerTargetId;
    }

    public String getAdminAccountId() {
        return adminAccountId;
    }

    public void setAdminAccountId(String adminAccountId) {
        this.adminAccountId = adminAccountId;
    }

    public String getAdminTpAccountId() {
        return adminTpAccountId;
    }

    public void setAdminTpAccountId(String adminTpAccountId) {
        this.adminTpAccountId = adminTpAccountId;
    }

    public Integer getUrlTimeOut() {
        return urlTimeOut;
    }

    public void setUrlTimeOut(Integer urlTimeOut) {
        this.urlTimeOut = urlTimeOut;
    }

    public int getAccessType() {
        return accessType;
    }

    public void setAccessType(int accessType) {
        this.accessType = accessType;
    }

    public String getAccessCode() {
        return accessCode;
    }

    public void setAccessCode(String accessCode) {
        this.accessCode = accessCode;
    }

    public String getNotifyUrl() {
        return notifyUrl;
    }

    public void setNotifyUrl(String notifyUrl) {
        this.notifyUrl = notifyUrl;
    }

    public int getIsSendSms() {
        return isSendSms;
    }

    public void setIsSendSms(int isSendSms) {
        this.isSendSms = isSendSms;
    }

    public Date getEffectiveTime() {
        return effectiveTime;
    }

    public void setEffectiveTime(Date effectiveTime) {
        this.effectiveTime = effectiveTime;
    }
}
